﻿using PlayerRoles.FirstPersonControl;
using PluginAPI.Core;
using PluginAPI.Core.Attributes;
using PluginAPI.Enums;
using PluginAPI.Events;
using System;
using System.Text;
using UnityEngine;
using Utils;


namespace RoleCustom.Event
{
    public class ClassDEvent
    {
        [PluginEvent(ServerEventType.PlayerSpawn)]
        public void OnPlayerSpawn(PlayerSpawnEvent ev)
        {
            TimeCoroutine.Delay(0.5f, () =>
            {
                if (ev.Player.Role != PlayerRoles.RoleTypeId.ClassD) return;

                string id = BadageTxtUtils.CreateClassD();

                ev.Player.ReferenceHub.serverRoles.SetColor("orange");
                ev.Player.ReferenceHub.serverRoles.SetText(id);

                ev.Player.AddItem(ItemType.Lantern);
                ev.Player.AddItem(ItemType.Painkillers);
                ev.Player.AddItem(ItemType.Flashlight);
                ev.Player.AddItem(ItemType.KeycardJanitor);
            });
        }


        [PluginEvent(ServerEventType.PlayerDeath)]
        public void OnPlayerDeath(PlayerDeathEvent ev)
        {
            if (ev.Player.Role != PlayerRoles.RoleTypeId.ClassD) return;

            ev.Player.ReferenceHub.serverRoles.SetColor("grey");
            ev.Player.ReferenceHub.serverRoles.SetText(string.Empty);
        }
    }
}
